package com.itheima.test.UDP.multicast;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class Service3 {//组播接受数据方3

    public static void main(String[] args) throws IOException {
        //组播码头为MulticastSocket
        MulticastSocket socket =new MulticastSocket(10000);
        byte[] bytes =new byte[1024];
        DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
        //joinGroup()加入到组播地址
        socket.joinGroup(InetAddress.getByName("224.0.1.0"));
        //解析输出
        socket.receive(packet);
        System.out.println(new String(packet.getData(),0, packet.getLength()));
        //释放资源
        socket.close();
    }
}
